package cn.wolfcode.trip.admin.controller;


import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.TravelCatalogQuery;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService catalogService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelCatalogQuery qo){
        model.addAttribute("pageInfo",catalogService.query(qo));
        model.addAttribute("strategies",strategyService.listAll());
        return "/strategyCatalog/list";
    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate( StrategyCatalog entity) {
        catalogService.saveOrUpdate(entity);
        return new JSONResult(); //象征性返回操作成功
    }
    @RequestMapping("listByStrategyId")
    @ResponseBody
    public Object listByStrategyId(Long strategyId) {
        return catalogService.listByStrategyId(strategyId);
    }
}
